package com.buka.order.Listener;

import com.buka.order.config.RabbitMqConfig;
import com.buka.order.service.TaskService;
import com.buka.pojo.Task;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class TimeListener {

    @Autowired
    private TaskService taskService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Scheduled(cron = "0 0/2 * * * ?")
    public void time(){
        List<Task> list = taskService.findList(new Task());
        if(list!=null&&list.size()>0){
            for (Task task : list){
                rabbitTemplate.convertAndSend("", task.getMqRoutingkey(),task);
            }
        }
    }
}
